package action;

import http.Response;
import http.ResponseBuilder;
import model.ApiResultModel;
import service.GroupService;

import java.util.Map;

public class GroupAction {

    public ResponseBuilder responseBuilder = new ResponseBuilder();

    public Response get_group_list(Map<String, String> params) {
        long user_id = Long.valueOf(params.getOrDefault("user_id", ""));
        ApiResultModel apiResultModel = GroupService.getGroupList(user_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response add_group(Map<String, String> params) {
        long admin_id = Long.valueOf(params.getOrDefault("admin_id", ""));
        String group_name = params.getOrDefault("group_name", "");
        ApiResultModel apiResultModel = GroupService.addGroup(admin_id, group_name);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response get_whiteboard_list(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        ApiResultModel apiResultModel = GroupService.getWhiteboardList(group_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response add_whiteboard(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        String whiteboard_name = params.getOrDefault("whiteboard_name", "");
        ApiResultModel apiResultModel = GroupService.addWhiteboard(group_id, whiteboard_name);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response get_member_list(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        ApiResultModel apiResultModel = GroupService.getMemberList(group_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response add_member(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        long user_id = Long.valueOf(params.getOrDefault("user_id", ""));
        ApiResultModel apiResultModel = GroupService.addMember(group_id, user_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response dismiss_group(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        ApiResultModel apiResultModel = GroupService.dismissGroup(group_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response remove_member(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        long user_id = Long.valueOf(params.getOrDefault("user_id", ""));
        ApiResultModel apiResultModel = GroupService.removeMember(user_id, group_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response remove_whiteboard(Map<String, String> params) {
        long group_id = Long.valueOf(params.getOrDefault("group_id", ""));
        long whiteboard_id = Long.valueOf(params.getOrDefault("whiteboard_id", ""));
        ApiResultModel apiResultModel = GroupService.removeBoard(group_id, whiteboard_id);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }
}
